package com.prd.controller;

import com.prd.dto.AttendanceDTO;
import com.prd.service.AttendanceService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.List;

/**
 *
 * @author lizhaoyi
 * @since 2023-10-03
 */
@Api(tags={"出勤管理"})
@RestController
@RequestMapping("/api/attendance")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;


    @ApiOperation("上班打卡")
    @PostMapping("clockIn")
    public JsonData clockIn(@RequestBody AttendanceDTO attendanceDto){

        return attendanceService.clockIn(attendanceDto);

    }

    @ApiOperation("下班打卡")
    @PostMapping("clockOut")
    public JsonData clockOut(@RequestBody AttendanceDTO attendanceDto){

        return attendanceService.clockOut(attendanceDto);

    }

    /**
     * 上传图片
     * 默认文件大小 10M,超过会报错
     * @param file
     * @return
     */
    @ApiOperation("上传图片")
    @PostMapping("uploadImg")
    public JsonData uploadImg(@ApiParam(value = "文件上传",required = true) @RequestPart("file") MultipartFile file){

        return attendanceService.uploadImg(file);
    }

    /**
     * 确认上传
     * @param urls
     * @param remark
     * @param attendanceId
     * @return
     */
    @ApiOperation("确认上传")
    @PostMapping("confirmUpload")
    public JsonData confirmUpload(@ApiParam(value = "图片路径") @RequestParam("urls") List<String> urls,
                              @ApiParam(value = "备注") @RequestParam(value = "remark") String remark,
                                  @ApiParam(value = "打卡记录id") @RequestParam String attendanceId){

        return attendanceService.confirmUpload(urls,remark,attendanceId);
    }

    /**
     * 日统计
     * @param clockDate
     * @return
     */
    @ApiOperation("日统计")
    @GetMapping(value = "getAttendancesByOneDay")
    public JsonData getAttendances(@ApiParam(value = "考勤日期") @RequestParam(value = "clockDate") @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate clockDate){

        return attendanceService.getAttendancesByOneDay(clockDate);

    }

    /**
     * 周统计
     * @return
     */
    @ApiOperation("周统计")
    @GetMapping(value = "getWeekAttendances")
    public JsonData getWeekAttendances(@ApiParam(value = "考勤日期") @RequestParam(value = "clockDate") @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate clockDate){

        return attendanceService.getWeekAttendances(clockDate);

    }


    /**
     * 月统计
     * @return
     */
    @ApiOperation("月统计")
    @GetMapping(value = "getMonthAttendances")
    public JsonData getMonthAttendances(@ApiParam(value = "考勤月份") @RequestParam(value = "clockMonth") String clockMonth){

        return attendanceService.getMonthAttendances(clockMonth);

    }

    /**
     * 是否已打卡
     * @return
     */
    @ApiOperation("是否已打卡")
    @PostMapping(value = "isClockOrNot")
    public JsonData isClockOrNot(){

        return attendanceService.isClockOrNot();
    }


}

